using System;

namespace Sunny.UI;

public class ConsoleLogger : BaseLogger
{
	public static ConsoleLogger Instance = new ConsoleLogger();

	private static readonly object obj = new object();

	public ConsoleLogger(LogLevel level = LogLevel.Info)
	{
		base.Level = level;
	}

	public override void WriteLog(string log)
	{
		Console.WriteLine(log);
	}

	public override void WriteLog(LogLevel level, string log)
	{
		lock (obj)
		{
			switch (level)
			{
			case LogLevel.Debug:
				Console.ForegroundColor = ConsoleColor.Cyan;
				break;
			case LogLevel.Info:
				Console.ForegroundColor = ConsoleColor.Green;
				break;
			case LogLevel.Warn:
				Console.ForegroundColor = ConsoleColor.Yellow;
				break;
			case LogLevel.Error:
				Console.ForegroundColor = ConsoleColor.Red;
				break;
			case LogLevel.Fatal:
				Console.ForegroundColor = ConsoleColor.Magenta;
				break;
			default:
				Console.ForegroundColor = ConsoleColor.Gray;
				break;
			}
			base.WriteLog(level, log);
			Console.ResetColor();
		}
	}
}
